﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class FinanceCenter_DownloadGatheringList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime StartTime = Shove._Convert.StrToDateTime(Request["StartTime"], DateTime.Now.ToShortDateString());
        DateTime EndTime = Shove._Convert.StrToDateTime(Request["EndTime"], DateTime.Now.ToShortDateString());
        
        string ReturnDescription = "";

        DataSet ds = null;

        DAL.Procedures.P_InComingOrOutComing(ref ds, StartTime, EndTime, 3, ref ReturnDescription);

        if (ds == null)
        {
            Shove._Web.JavaScript.Alert(this.Page, "数据库连接失败。");

            return;
        }

        DataTable dt = ds.Tables[0];
        if (dt == null)
        {
            Shove._Web.JavaScript.Alert(this.Page, "数据库连接失败。");

            return;
        }

        HttpResponse response;
        response = Page.Response;
        response.AppendHeader("Content-Disposition", "attachment;filename=GatheringList_" + DateTime.Now.ToString("yyyyMMdd") + ".xls");
        Response.ContentType = "application/ms-excel";
        response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

        response.Write("序号\t会员ID\t会员姓名\t入款金额\t入款时间\t入款方式\t操作员\t备注 \n");

        foreach (DataRow dr in dt.Rows)
        {
            response.Write(dr["sequenceNumber"].ToString() + "\t" + dr["CustomerNo"].ToString() + "\t" + dr["CustomerName"].ToString() + "\t" + dr["Money"].ToString() + "\t" + dr["DateTime"].ToString() + "\t" + (dr["PayNumber"].ToString().Replace("&nbsp;", "") != "" ? "支付宝支付" : "银联支付") + "\t" + dr["OperatorCustomerNo"].ToString() + "\t" + dr["memo"].ToString() + "\n");
        }

        if (ds.Tables[1].Rows.Count > 0)
        {
            string strMoney = ds.Tables[1].Rows[0]["SumMoney"].ToString();
            response.Write("总计：" + ds.Tables[1].Rows[0]["SumID"].ToString() + "   总计：消费" + ((Shove._Convert.StrToDouble(strMoney, 0) == 0) ? "0.00" : Shove._Convert.StrToDouble(strMoney, 0).ToString()));
        }

        response.End();
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        //RequestCompetences = Competences.BuildCompetencesList(Competences.Finance);
        RequestLoginPage = this.Request.Url.AbsoluteUri;

        base.OnInit(e);
    }

    #endregion
}
